#传统动态类型代码实例
# def calculate(a, b):
#     return a + b #无法直接观看出参数类型和返回值类型
#
# result1 = calculate(3,5) #正确写法
# result2 = calculate('3',5) #错误写法

# age:int = 18
# name:str = "小王"
# price:float = 9.99
# is_valid:bool = True
# data:bytes = b'hello world'
# print(age,name,price,is_valid,data)
#
# def add (a:int,b:int):
#     return a+b

from typing import List, Dict, Union,Tuple,Literal,Optional,NewType

# source:List[int] = [1,2,3,4,"xx"]
# config:Dict[str,Union[int,str]] = {"name":"小王","age":18,"xxoo":"33xxx"}
# print(config)
#
# flexible:Tuple[str,...] = ("a","b","c","c")
# print(flexible)
#
#
# # def debug_log(obj:Any) -> None:
# #     print(repr(obj))
# #
# # print(debug_log())
#
# HttpMethod=Literal["GET","POST"]
# def request(method:HttpMethod,url:str) -> None:
#     print(method,url)
#
# request("GET","https://www.baidu.com")

# def process_input(value:Union[int,str]) -> None:
#     if isinstance(value,int):
#         print(value)
#     elif isinstance(value,str):
#         print(value)
#     else:
#         raise TypeError("Invalid type")
#
# process_input(23)
# process_input("23")
# process_input( (1,3,4))

# def greet1(name: Optional[str] =None) ->str:
#     if name:
#         return f"Hello, {name}!"
#     else:
#         return "Hello!"
# def greet2(name:Optional[str]) -> str:
#     if name:
#         return f"Hello, {name}!"
#     else:
#         return "Hello!"
# print((greet1("小王")))
# print(greet1())
# print(greet2(greet2("小王1")))
# print(greet2()) #必须要有参数

# UserId = int
# Point = Tuple[int,int]
# def move_user(user_id:UserId,point:Point) -> None:
#     print(user_id,point)
# def move_user2(ids:Point) -> None:
#     for id in ids:
#         print(id)
# print(move_user2((1,2,3,4,5,6,7,8,9,10)))

# UserId = NewType('UserId', int)
# admin_id = UserId(1)
# def print_id(user_id: UserId) -> None:
#     print(user_id)
# print(print_id(11))